package com.wyx;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import com.aliyuncs.exceptions.ClientException;
import org.junit.jupiter.api.Test;

import java.io.FileInputStream;

public class Upload {
    @Test
    public void test() throws ClientException {
        String endpoint = "https://oss-cn-beijing.aliyuncs.com";
        String ACCESS_KEY_ID = "LTAI5tDGZrCwFbb8Sm2rEthS";
        String ACCESS_KEY_SECRET = "tqpQmLNHmfuOscDIPmUMYobSoCBqtO";
        String bucket = "20250227";
        String objectName = "c895e8b8-9179-4625-971f-d36d7b668e06.png";
        OSS ossClient = new OSSClientBuilder().build(endpoint, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
        try{
            String content = "Hello OSS";
            PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, objectName, new FileInputStream("D:\\Users\\WYX\\Documents\\GitHub\\SpringBoot\\SpringBoot\\BlogSystem\\file\\c895e8b8-9179-4625-971f-d36d7b668e06.png"));
            PutObjectResult result=ossClient.putObject(putObjectRequest);
            System.out.println(result.getRequestId());
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
}
